/**
    Copyright (C) 2011  Alexander Vollmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jefb.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "CV_FILE")
public class FileEntity extends BasicEntity implements Serializable,
		Comparable<FileEntity> {
	private static final long serialVersionUID = 8748468733472299604L;

	private String name;
	private String workspace; 
	private String path;
	private Long size;
	private String description;
	private String md5Hash;
	private Date registrationTime;
	private String storageName;
	private boolean directory;

	// s334
	private	Collection<DestinationEntity> destinations = new ArrayList<DestinationEntity>();

	public FileEntity() {
		super();
	}

	public FileEntity(String name) {
		super();
		this.name = name;
	}
	
	public FileEntity(String name, String path, String workspace) {
		super();
		this.name = name;
		this.path = path;
		this.workspace = workspace;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "CV_FILE_DESTINATION", joinColumns = { @JoinColumn(name = "FILE_ID") }, inverseJoinColumns = { @JoinColumn(name = "DEST_ID") })
	public Collection<DestinationEntity> getDestinations() {
		return destinations;
	}

	@Column(name = "NAME", nullable = false)
	public String getName() {
		return name;
	}
	
	@Column(name = "PATH", nullable = true)
	public String getPath() {
		return path;
	}
	
	@Column(name = "WORKSPACE", nullable = true)
	public String getWorkspace() {
		return workspace;
	}

	@Column(name = "FILE_SIZE")
	public Long getSize() {
		return size;
	}

	@Column(name = "DESCRIPTION", nullable = true)
	public String getDescription() {
		return description;
	}

	@Column(name = "MD5HASH", nullable = true)
	public String getMd5Hash() {
		return md5Hash;
	}

	@Column(name = "REGISTRATION_TIME", nullable = true)
	public Date getRegistrationTime() {
		return registrationTime;
	}

	@Column(name = "STORAGE_NAME", nullable = true)
	public String getStorageName() {
		return storageName;
	}
	
	@Column(name = "DIRECTORY", nullable = true)
	public boolean getDirectory() {
		return directory;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setMd5Hash(String md5Hash) {
		this.md5Hash = md5Hash;
	}

	public void setRegistrationTime(Date registrationTime) {
		this.registrationTime = registrationTime;
	}

	public int compareTo(FileEntity o) {
		return 0;
	}

	public void setStorageName(String storageName) {
		this.storageName = storageName;
	}

	public void setDestinations(Collection<DestinationEntity> destinations) {
		this.destinations = destinations;
	}

	public void setPath(String path) {this.path = path;}
	public void setDirectory(boolean directory) {this.directory = directory;}

	public void setWorkspace(String workspace) {this.workspace = workspace;}
}
